home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / dshow / PropPage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-04  |  19.2 KB  |  714 lines

  1. /*
  2.  *    MPEG Audio Encoder for DirectShow
  3.  *    Basic property page
  4.  *
  5.  *    Copyright (c) 2000 Marie Orlova, Peter Gubanov, Elecard Ltd.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the
  19.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20.  * Boston, MA 02111-1307, USA.
  21.  */
  22.  
  23. #include <streams.h>
  24. #include <olectl.h>
  25. #include <olectlid.h>
  26. #include <commctrl.h>
  27. #include "iaudioprops.h"
  28. #include "mpegac.h"
  29. #include "resource.h"
  30. #include "PropPage.h"
  31. #include "Reg.h"
  32.  
  33. // Strings which apear in comboboxes
  34. const char *szBitRateString[2][14] = {
  35.     {
  36.         "32 kbps","40 kbps","48 kbps","56 kbps",
  37.         "64 kbps","80 kbps","96 kbps","112 kbps",
  38.         "128 kbps","160 kbps","192 kbps","224 kbps",
  39.         "256 kbps","320 kbps"
  40.     },
  41.     {
  42.         "8 kbps","16 kbps","24 kbps","32 kbps",
  43.         "40 kbps","48 kbps","56 kbps","64 kbps",
  44.         "80 kbps","96 kbps","112 kbps","128 kbps",
  45.         "144 kbps","160 kbps"
  46.     }
  47. };
  48.  
  49. LPCSTR szQualityDesc[10] = {
  50.     "High", "High", "High", "High", "High",
  51.     "Medium", "Medium",
  52.     "Low", "Low",
  53.     "Fast mode"
  54. };
  55.  
  56. LPCSTR szVBRqDesc[10] = {
  57.     "0 - ~1:4",
  58.     "1 - ~1:5",
  59.     "2 - ~1:6",
  60.     "3 - ~1:7",
  61.     "4 - ~1:9",
  62.     "5 - ~1:9",
  63.     "6 - ~1:10",
  64.     "7 - ~1:11",
  65.     "8 - ~1:12",
  66.     "9 - ~1:14"
  67. };
  68. struct SSampleRate {
  69.     DWORD dwSampleRate;
  70.     LPCSTR lpSampleRate;
  71. };
  72. SSampleRate srRates[6] = {
  73.     {48000, "48 kHz"},
  74.     {44100, "44.1 kHz"},
  75.     {32000, "32 kHz"},
  76.     {24000, "24 kHz"},
  77.     {22050, "22.05 kHz"},
  78.     {16000, "16 kHz"}
  79. };
  80.  
  81. ////////////////////////////////////////////////////////////////
  82. // CreateInstance
  83. ////////////////////////////////////////////////////////////////
  84. CUnknown *CMpegAudEncPropertyPage::CreateInstance( LPUNKNOWN punk, HRESULT *phr )
  85. {
  86.     CMpegAudEncPropertyPage *pNewObject
  87.         = new CMpegAudEncPropertyPage( punk, phr );
  88.  
  89.     if( pNewObject == NULL )
  90.         *phr = E_OUTOFMEMORY;
  91.  
  92.     return pNewObject;
  93. }
  94.  
  95. ////////////////////////////////////////////////////////////////
  96. // Constructor
  97. ////////////////////////////////////////////////////////////////
  98. CMpegAudEncPropertyPage::CMpegAudEncPropertyPage(LPUNKNOWN punk, HRESULT *phr)
  99.  : CBasePropertyPage(NAME("Encoder Property Page"), 
  100.                       punk, IDD_AUDIOENCPROPS, IDS_AUDIO_PROPS_TITLE)                      
  101.     , m_pAEProps(NULL)
  102.     , m_fWindowInactive(TRUE)
  103. {
  104.     ASSERT(phr);
  105.  
  106.     InitCommonControls();
  107. }
  108.  
  109. //
  110. // OnConnect
  111. //
  112. // Give us the filter to communicate with
  113. HRESULT CMpegAudEncPropertyPage::OnConnect(IUnknown *pUnknown)
  114. {
  115.     ASSERT(m_pAEProps == NULL);
  116.  
  117.     // Ask the filter for it's control interface
  118.  
  119.     HRESULT hr = pUnknown->QueryInterface(IID_IAudioEncoderProperties,(void **)&m_pAEProps);
  120.     if (FAILED(hr)) {
  121.         return E_NOINTERFACE;
  122.     }
  123.  
  124.     ASSERT(m_pAEProps);
  125.  
  126.     // Get current filter state
  127.     m_pAEProps->LoadAudioEncoderPropertiesFromRegistry();
  128.     m_pAEProps->get_PESOutputEnabled(&m_dwPES);
  129.     m_pAEProps->get_Bitrate(&m_dwBitrate);
  130.     m_pAEProps->get_Variable(&m_dwVariable);
  131.     m_pAEProps->get_VariableMin(&m_dwMin);
  132.     m_pAEProps->get_VariableMax(&m_dwMax);
  133.     m_pAEProps->get_Quality(&m_dwQuality);
  134.     m_pAEProps->get_VariableQ(&m_dwVBRq);
  135.     m_pAEProps->get_SampleRate(&m_dwSampleRate);
  136.     m_pAEProps->get_ChannelMode(&m_dwChannelMode);
  137.     m_pAEProps->get_CRCFlag(&m_dwCRC);
  138.     m_pAEProps->get_CopyrightFlag(&m_dwCopyright);
  139.     m_pAEProps->get_OriginalFlag(&m_dwOriginal);
  140.  
  141.     return NOERROR;
  142. }
  143.  
  144. //
  145. // OnDisconnect
  146. //
  147. // Release the interface
  148.  
  149. HRESULT CMpegAudEncPropertyPage::OnDisconnect()
  150. {
  151.     // Release the interface
  152.     if (m_pAEProps == NULL) {
  153.         return E_UNEXPECTED;
  154.     }
  155.  
  156.     m_pAEProps->set_PESOutputEnabled(m_dwPES);
  157.     m_pAEProps->set_Bitrate(m_dwBitrate);
  158.     m_pAEProps->set_Variable(m_dwVariable);
  159.     m_pAEProps->set_VariableMin(m_dwMin);
  160.     m_pAEProps->set_VariableMax(m_dwMax);
  161.     m_pAEProps->set_Quality(m_dwQuality);
  162.     m_pAEProps->set_VariableQ(m_dwVBRq);
  163.     m_pAEProps->set_SampleRate(m_dwSampleRate);
  164.     m_pAEProps->set_ChannelMode(m_dwChannelMode);
  165.     m_pAEProps->set_CRCFlag(m_dwCRC);
  166.     m_pAEProps->set_CopyrightFlag(m_dwCopyright);
  167.     m_pAEProps->set_OriginalFlag(m_dwOriginal);
  168.     m_pAEProps->SaveAudioEncoderPropertiesToRegistry();
  169.  
  170.     m_pAEProps->Release();
  171.     m_pAEProps = NULL;
  172.     return NOERROR;
  173. }
  174.  
  175. //
  176. // OnActivate
  177. //
  178. // Called on dialog creation
  179.  
  180. HRESULT CMpegAudEncPropertyPage::OnActivate(void)
  181. {
  182.     InitPropertiesDialog(m_hwnd);
  183.  
  184.     m_fWindowInactive = FALSE;
  185.  
  186.     return NOERROR;
  187. }
  188.  
  189. //
  190. // OnDeactivate
  191. //
  192. // Called on dialog destruction
  193.  
  194. HRESULT CMpegAudEncPropertyPage::OnDeactivate(void)
  195. {
  196.     m_fWindowInactive = TRUE;
  197.     return NOERROR;
  198. }
  199.  
  200. ////////////////////////////////////////////////////////////////
  201. // OnReceiveMessage - message handler function
  202. ////////////////////////////////////////////////////////////////
  203. BOOL CMpegAudEncPropertyPage::OnReceiveMessage(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  204. {
  205.     switch( uMsg )
  206.     {
  207.     case WM_HSCROLL:
  208.         if ((HWND)lParam == m_hwndQuality) {
  209.             int pos = SendMessage(m_hwndQuality,TBM_GETPOS,0,0);
  210.             if (pos>=0 && pos<10) {
  211.                 SetDlgItemText(hwnd,IDC_TEXT_QUALITY,szQualityDesc[pos]);
  212.                 m_pAEProps->set_Quality(pos);
  213.                 SetDirty();
  214.             }
  215.         }
  216.         break;
  217.  
  218.     case WM_COMMAND:
  219.         switch (LOWORD(wParam))
  220.         {
  221.         case IDC_COMBO_CBR:
  222.             if (HIWORD(wParam) == CBN_SELCHANGE)
  223.             {
  224.                 int nBitrate = SendDlgItemMessage(hwnd,IDC_COMBO_CBR,CB_GETCURSEL,0,0L);
  225.                 DWORD dwSampleRate;
  226.                 m_pAEProps->get_SampleRate(&dwSampleRate);
  227.                 DWORD dwBitrate;
  228.  
  229.                 if (dwSampleRate >= 32000)
  230.                 {
  231.                     // Consider MPEG 1
  232.                     dwBitrate = dwBitRateValue[0][nBitrate];
  233.                 }
  234.                 else
  235.                 {
  236.                     // Consider MPEG 2
  237.                     dwBitrate = dwBitRateValue[1][nBitrate];
  238.                 }
  239.  
  240.                 m_pAEProps->set_Bitrate(dwBitrate);
  241.  
  242.                 SetDirty();
  243.             }
  244.             break;
  245.  
  246.         case IDC_COMBO_VBRMIN:
  247.             if (HIWORD(wParam) == CBN_SELCHANGE)
  248.             {
  249.                 int nVariableMin = SendDlgItemMessage(hwnd,IDC_COMBO_VBRMIN,CB_GETCURSEL,0,0L);
  250.                 DWORD dwSampleRate;
  251.                 m_pAEProps->get_SampleRate(&dwSampleRate);
  252.                 DWORD dwMin;
  253.  
  254.                 if (dwSampleRate >= 32000)
  255.                 {
  256.                     // Consider MPEG 1
  257.                     dwMin = dwBitRateValue[0][nVariableMin];
  258.                 }
  259.                 else
  260.                 {
  261.                     // Consider MPEG 2
  262.                     dwMin = dwBitRateValue[1][nVariableMin];
  263.                 }
  264.  
  265.                 m_pAEProps->set_VariableMin(dwMin);
  266.  
  267.                 SetDirty();
  268.             }
  269.             break;
  270.  
  271.         case IDC_COMBO_VBRMAX:
  272.             if (HIWORD(wParam) == CBN_SELCHANGE)
  273.             {
  274.                 int nVariableMax = SendDlgItemMessage(hwnd,IDC_COMBO_VBRMAX,CB_GETCURSEL,0,0L);
  275.                 DWORD dwSampleRate;
  276.                 m_pAEProps->get_SampleRate(&dwSampleRate);
  277.                 DWORD dwMax;
  278.  
  279.                 if (dwSampleRate >= 32000)
  280.                 {
  281.                     // Consider MPEG 1
  282.                     dwMax = dwBitRateValue[0][nVariableMax];
  283.                 }
  284.                 else
  285.                 {
  286.                     // Consider MPEG 2
  287.                     dwMax = dwBitRateValue[1][nVariableMax];
  288.                 }
  289.  
  290.                 m_pAEProps->set_VariableMax(dwMax);
  291.  
  292.                 SetDirty();
  293.             }
  294.             break;
  295.     
  296.  
  297.         case IDC_COMBO_SAMPLE_RATE:
  298.             if (HIWORD(wParam) == CBN_SELCHANGE)
  299.             {
  300.                 int nSampleRate = SendDlgItemMessage(hwnd, IDC_COMBO_SAMPLE_RATE, CB_GETCURSEL, 0, 0L);
  301.                 //DWORD dwSourceSampleRate;
  302.                 //m_pAEProps->get_SourceSampleRate(&dwSourceSampleRate);
  303.  
  304.                 DWORD dwSampleRate;
  305.             
  306.                 if ((nSampleRate >= 0) && (nSampleRate < 6)){
  307.                 dwSampleRate = srRates[nSampleRate].dwSampleRate;
  308.                 }
  309.                 m_pAEProps->set_SampleRate(dwSampleRate);
  310.                 InitPropertiesDialog(hwnd);
  311.                 SetDirty();
  312.             }
  313.             break;
  314.  
  315.         case IDC_COMBO_VBRq:
  316.             if (HIWORD(wParam) == CBN_SELCHANGE)
  317.             {
  318.                 int nVBRq = SendDlgItemMessage(hwnd, IDC_COMBO_VBRq, CB_GETCURSEL, 0, 0L);
  319.                 if (nVBRq >=0 && nVBRq <=9) 
  320.                     m_pAEProps->set_VariableQ(nVBRq);
  321.                 SetDirty();
  322.             }
  323.             break;
  324.  
  325.         case IDC_RADIO_CBR:
  326.         case IDC_RADIO_VBR:
  327.             m_pAEProps->set_Variable(LOWORD(wParam)-IDC_RADIO_CBR);
  328.             SetDirty();
  329.             break;
  330.  
  331. /*        case IDC_COMBO_CHMOD:
  332.             if (HIWORD(wParam) == CBN_SELCHANGE)
  333.             {
  334.                 int nChannelMode = SendDlgItemMessage(hwnd, IDC_COMBO_CHMOD, CB_GETCURSEL, 0, 0L);
  335.                 DWORD dwChannelMode;
  336.  
  337.                 switch(nChannelMode) 
  338.                 {
  339.                     case 0: 
  340.                         dwChannelMode = MPGA_CHMOD_MONO;
  341.                         break;
  342.                     case 1:
  343.                         dwChannelMode = MPGA_CHMOD_STEREO;
  344.                         break;
  345.                     case 2:
  346.                         dwChannelMode = MPGA_CHMOD_JOINT;
  347.                         break;
  348.                     case 3:
  349.                         dwChannelMode = MPGA_CHMOD_DUAL;
  350.                         break;
  351.                     default:
  352.                         m_pAEProps->get_ChannelMode(&dwChannelMode);
  353.                         break;
  354.                 }
  355.  
  356.                 m_pAEProps->set_ChannelMode(dwChannelMode);
  357.  
  358.                 SetDirty();
  359.             }
  360.             break;
  361. */
  362.         case IDC_CHECK_PES:
  363.             m_pAEProps->set_PESOutputEnabled(IsDlgButtonChecked(hwnd, IDC_CHECK_PES));
  364.             SetDirty();
  365.             break;
  366.  
  367.         case IDC_CHECK_COPYRIGHT:
  368.             m_pAEProps->set_CopyrightFlag(IsDlgButtonChecked(hwnd, IDC_CHECK_COPYRIGHT));
  369.             SetDirty();
  370.             break;
  371.  
  372.         case IDC_CHECK_ORIGINAL:
  373.             m_pAEProps->set_OriginalFlag(IsDlgButtonChecked(hwnd, IDC_CHECK_ORIGINAL));
  374.             SetDirty();
  375.             break;
  376.  
  377.         case IDC_CHECK_CRC:
  378.             m_pAEProps->set_CRCFlag(IsDlgButtonChecked(hwnd, IDC_CHECK_CRC));
  379.             SetDirty();
  380.             break;
  381.         }
  382.         return TRUE;
  383.  
  384.     case WM_DESTROY:
  385.         return TRUE;
  386.  
  387.     default:
  388.         return FALSE;
  389.     }
  390.  
  391.     return TRUE;
  392. }
  393.  
  394. //
  395. // OnApplyChanges
  396. //
  397. HRESULT CMpegAudEncPropertyPage::OnApplyChanges() 
  398. {
  399.     m_pAEProps->get_PESOutputEnabled(&m_dwPES);
  400.     m_pAEProps->get_Bitrate(&m_dwBitrate);
  401.     m_pAEProps->get_Variable(&m_dwVariable);
  402.     m_pAEProps->get_VariableMin(&m_dwMin);
  403.     m_pAEProps->get_VariableMax(&m_dwMax);
  404.     m_pAEProps->get_Quality(&m_dwQuality);
  405.     m_pAEProps->get_VariableQ(&m_dwVBRq);
  406.     m_pAEProps->get_SampleRate(&m_dwSampleRate);
  407.     m_pAEProps->get_ChannelMode(&m_dwChannelMode);
  408.     m_pAEProps->get_CRCFlag(&m_dwCRC);
  409.     m_pAEProps->get_CopyrightFlag(&m_dwCopyright);
  410.     m_pAEProps->get_OriginalFlag(&m_dwOriginal);
  411.     m_pAEProps->SaveAudioEncoderPropertiesToRegistry();
  412.  
  413.     return S_OK; 
  414. }
  415.  
  416. //
  417. // Initialize dialogbox controls with proper values
  418. //
  419. void CMpegAudEncPropertyPage::InitPropertiesDialog(HWND hwndParent)
  420. {
  421.     EnableControls(hwndParent, TRUE);
  422.  
  423.     m_hwndQuality = GetDlgItem(hwndParent,IDC_SLIDER_QUALITY);
  424.     DWORD dwQuality;
  425.     m_pAEProps->get_Quality(&dwQuality);
  426.     SendDlgItemMessage(hwndParent, IDC_SLIDER_QUALITY, TBM_SETRANGE, 1, MAKELONG (2,9));
  427.     SendDlgItemMessage(hwndParent, IDC_SLIDER_QUALITY, TBM_SETPOS, 1, dwQuality);
  428.     if (dwQuality>=0 && dwQuality<10)
  429.         SetDlgItemText(hwndParent,IDC_TEXT_QUALITY,szQualityDesc[dwQuality]);
  430.  
  431.     //
  432.     // initialize sample rate selection
  433.     //
  434.     DWORD dwSourceSampleRate;
  435.     m_pAEProps->get_SourceSampleRate(&dwSourceSampleRate);
  436.     /*    switch (dwSourceSampleRate) 
  437.     {
  438.         case 48000: 
  439.         {    
  440.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"48 kHz");
  441.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"24 kHz");
  442.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"16 kHz");
  443.             break; 
  444.         }
  445.         case 44100: 
  446.         {
  447.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"44.1 kHz");
  448.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"22.05 kHz");
  449.             break; 
  450.         }
  451.         case 32000: 
  452.         {
  453.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"32 kHz");
  454.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"16 kHz");
  455.             break; 
  456.         }
  457.         case 24000:    
  458.         {
  459.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"24 kHz");
  460.             break; 
  461.         }
  462.         case 22050:    
  463.         {
  464.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"22.05 kHz");
  465.             break; 
  466.         }
  467.         case 16000:    
  468.         {
  469.             SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"16 kHz");
  470.             break; 
  471.         }
  472.     }*/
  473.  
  474.  
  475.     SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_RESETCONTENT, 0, 0L);
  476.     for (int i = 0; i<6; i++)
  477.         SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)srRates[i].lpSampleRate);
  478.     DWORD dwSampleRate;
  479.     m_pAEProps->get_SampleRate(&dwSampleRate);
  480.     m_pAEProps->set_SampleRate(dwSampleRate);
  481.     
  482.     //int nSF = (dwSourceSampleRate/dwSampleRate - 1);
  483.     //if (nSF < 0)
  484.     //    nSF = 0;
  485.     
  486.     int nSR = 0;
  487.     while (dwSampleRate != srRates[nSR].dwSampleRate && nSR<6){
  488.         nSR++;
  489.     }
  490.     SendDlgItemMessage(hwndParent, IDC_COMBO_SAMPLE_RATE, CB_SETCURSEL, nSR, 0);
  491.  
  492.  
  493.     DWORD dwChannels;
  494.     m_pAEProps->get_SourceChannels(&dwChannels);
  495.  
  496.     /*
  497.     SendDlgItemMessage(hwndParent, IDC_COMBO_CHMOD, CB_RESETCONTENT, 0, 0L);
  498.     if(dwChannels == 2)
  499.     {    for(int i = 0; i < 4; i++)
  500.             SendDlgItemMessage(hwndParent, IDC_COMBO_CHMOD, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)chChMode[i]);
  501.     }
  502.     else
  503.         SendDlgItemMessage(hwndParent, IDC_COMBO_CHMOD, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)chChMode[0]);
  504.     */
  505. //
  506. //initialize VBRq combo box
  507. //
  508.     int k;
  509.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRq, CB_RESETCONTENT, 0, 0);
  510.         for (k=0; k<10; k++)
  511.         SendDlgItemMessage(hwndParent, IDC_COMBO_VBRq, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szVBRqDesc[k]);
  512.     DWORD dwVBRq;
  513.     m_pAEProps->get_VariableQ(&dwVBRq);
  514.     if (dwVBRq<0)
  515.         dwVBRq = 0;
  516.     if (dwVBRq>9)
  517.         dwVBRq = 9;
  518.     m_pAEProps->set_VariableQ(dwVBRq);
  519.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRq, CB_SETCURSEL, dwVBRq, 0);
  520.  
  521. //////////////////////////////////////
  522.     // initialize CBR selection
  523. //////////////////////////////////////
  524.     int nSt;
  525.  
  526.     SendDlgItemMessage(hwndParent, IDC_COMBO_CBR, CB_RESETCONTENT, 0, 0);
  527.     if (dwSampleRate >= 32000)
  528.     {    
  529.         // If target sampling rate is less than 32000, consider
  530.         // MPEG 1 audio
  531.         nSt = 0;
  532.         for (int i=0; i<14 ;i++)
  533.             SendDlgItemMessage(hwndParent, IDC_COMBO_CBR, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[0][i]);
  534.     }
  535.     else
  536.     {    
  537.         // Consider MPEG 2 audio
  538.         nSt = 1;
  539.         for (int i=0; i<14 ;i++)
  540.             SendDlgItemMessage(hwndParent, IDC_COMBO_CBR, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[1][i]);
  541.     }
  542.  
  543.     DWORD dwBitrate;
  544.     m_pAEProps->get_Bitrate(&dwBitrate);
  545.  
  546.     int nBitrateSel = 0;
  547.     // BitRateValue[][i] is in ascending order
  548.     // We use this fact. We also know there are 14 bitrate values available.
  549.     // We are going to use the closest possible, so we can limit loop with 13
  550.     while (nBitrateSel<13 && dwBitRateValue[nSt][nBitrateSel] < dwBitrate)
  551.         nBitrateSel++;
  552.     SendDlgItemMessage(hwndParent, IDC_COMBO_CBR, CB_SETCURSEL, nBitrateSel, 0);
  553.     
  554.     // check if the specified bitrate is found exactly and correct if not
  555.     if (dwBitRateValue[nSt][nBitrateSel] != dwBitrate)
  556.     {
  557.         dwBitrate = dwBitRateValue[nSt][nBitrateSel];
  558.         // we can change it, because it is independent of any other parameters
  559.         // (but depends on some of them!)
  560.         m_pAEProps->set_Bitrate(dwBitrate);
  561.     }
  562.  
  563.     //
  564.     // Check VBR/CBR radio button
  565.     //
  566.     DWORD dwVariable;
  567.     m_pAEProps->get_Variable(&dwVariable);
  568. /*
  569.     if (dwVariable)
  570.         SendDlgItemMessage(hwndParent, IDC_RADIO_VBR, BM_SETCHECK, 1, 0);
  571.     else
  572.         SendDlgItemMessage(hwndParent, IDC_RADIO_CBR, BM_SETCHECK, 1, 0);
  573. */
  574.     CheckRadioButton(hwndParent,IDC_RADIO_CBR,IDC_RADIO_VBR,IDC_RADIO_CBR+dwVariable);
  575.  
  576. //////////////////////////////////////////////////
  577.     // initialize VBR selection
  578. //////////////////////////////////////////////////
  579.     //VBRMIN, VBRMAX
  580.     int j, nST;
  581.  
  582.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMIN, CB_RESETCONTENT, 0, 0);
  583.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMAX, CB_RESETCONTENT, 0, 0);
  584.  
  585.     if (dwSampleRate >= 32000) {
  586.             nST = 0;
  587.             for (j=0; j<14 ;j++) {
  588.                 SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMIN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[0][j]);
  589.                 SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMAX, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[0][j]);
  590.             }
  591.     }
  592.     else {
  593.             nST = 1;
  594.             for (j=0; j<14 ;j++) {
  595.                 SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMIN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[1][j]);
  596.                 SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMAX, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBitRateString[1][j]);
  597.             }
  598.     }
  599.  
  600.     DWORD dwMin,dwMax;
  601.     m_pAEProps->get_VariableMin(&dwMin);
  602.     m_pAEProps->get_VariableMax(&dwMax);
  603.  
  604.     int nVariableMinSel = 0;
  605.     int nVariableMaxSel = 0;
  606.     
  607.     // BitRateValue[][i] is in ascending order
  608.     // We use this fact. We also know there are 14 bitrate values available.
  609.     // We are going to use the closest possible, so we can limit loop with 13
  610.     while (nVariableMinSel<13 && dwBitRateValue[nST][nVariableMinSel] < dwMin)
  611.         nVariableMinSel++;
  612.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMIN, CB_SETCURSEL, nVariableMinSel, 0);
  613.  
  614.     while (nVariableMaxSel<13 && dwBitRateValue[nST][nVariableMaxSel] < dwMax)
  615.         nVariableMaxSel++;
  616.     SendDlgItemMessage(hwndParent, IDC_COMBO_VBRMAX, CB_SETCURSEL, nVariableMaxSel, 0);
  617.  
  618.     
  619.     // check if the specified bitrate is found exactly and correct if not
  620.     if (dwBitRateValue[nST][nVariableMinSel] != dwMin)
  621.     {
  622.         dwMin = dwBitRateValue[nST][nVariableMinSel];
  623.         // we can change it, because it is independent of any other parameters
  624.         // (but depends on some of them!)
  625.         m_pAEProps->set_VariableMin(dwMin);
  626.     }
  627.  
  628.     // check if the specified bitrate is found exactly and correct if not
  629.     if (dwBitRateValue[nST][nVariableMaxSel] != dwMax)
  630.     {
  631.         dwMax = dwBitRateValue[nST][nVariableMaxSel];
  632.         // we can change it, because it is independent of any other parameters
  633.         // (but depends on some of them!)
  634.         m_pAEProps->set_VariableMax(dwMax);
  635.     }
  636.     
  637.     
  638.     //
  639.     // initialize checkboxes
  640.     //
  641.     DWORD dwPES;
  642.     m_pAEProps->get_PESOutputEnabled(&dwPES);
  643.  
  644.     CheckDlgButton(hwndParent, IDC_CHECK_PES, dwPES ? BST_CHECKED : BST_UNCHECKED);
  645. /*
  646.     DWORD dwChannelMode;
  647.     m_pAEProps->get_ChannelMode(&dwChannelMode);
  648.  
  649.     int iChannelMode;
  650.     switch (dwChannelMode)
  651.     {
  652.     case MPGA_CHMOD_MONO:
  653.         iChannelMode = 0;
  654.         break;
  655.     case MPGA_CHMOD_STEREO:
  656.         iChannelMode = 1;
  657.         break;
  658.     case MPGA_CHMOD_JOINT:
  659.         iChannelMode = 2;
  660.         break;
  661.     case MPGA_CHMOD_DUAL:
  662.         iChannelMode = 3;
  663.         break;
  664.     default:
  665.         iChannelMode = 0;
  666.         break;
  667.     }
  668.     SendDlgItemMessage(hwndParent, IDC_COMBO_CHMOD, CB_SETCURSEL, iChannelMode, 0);
  669. */
  670.     DWORD dwCRC;
  671.     m_pAEProps->get_CRCFlag(&dwCRC);
  672.     CheckDlgButton(hwndParent, IDC_CHECK_CRC, dwCRC ? BST_CHECKED : BST_UNCHECKED);
  673.  
  674.     DWORD dwCopyright;
  675.     m_pAEProps->get_CopyrightFlag(&dwCopyright);
  676.     CheckDlgButton(hwndParent, IDC_CHECK_COPYRIGHT, dwCopyright ? BST_CHECKED : BST_UNCHECKED);
  677.  
  678.     DWORD dwOriginal;
  679.     m_pAEProps->get_OriginalFlag(&dwOriginal);
  680.     CheckDlgButton(hwndParent, IDC_CHECK_ORIGINAL, dwOriginal ? BST_CHECKED : BST_UNCHECKED);
  681. }
  682.  
  683.  
  684. ////////////////////////////////////////////////////////////////
  685. // EnableControls
  686. ////////////////////////////////////////////////////////////////
  687. void CMpegAudEncPropertyPage::EnableControls(HWND hwndParent, bool bEnable)
  688. {   
  689.     EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_PES), bEnable);
  690.     EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_CBR), bEnable);
  691.     EnableWindow(GetDlgItem(hwndParent, IDC_COMBO_CBR), bEnable);
  692.     EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_VBR), bEnable);
  693.     EnableWindow(GetDlgItem(hwndParent, IDC_COMBO_VBRMIN), bEnable);
  694.     EnableWindow(GetDlgItem(hwndParent, IDC_COMBO_VBRMAX), bEnable);
  695.     EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_COPYRIGHT), bEnable);
  696.     EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_ORIGINAL), bEnable);
  697.     EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_CRC), bEnable);
  698.     EnableWindow(GetDlgItem(hwndParent, IDC_SLIDER_QUALITY), bEnable);
  699.     EnableWindow(GetDlgItem(hwndParent, IDC_COMBO_SAMPLE_RATE), bEnable);
  700. }
  701.  
  702. //
  703. // SetDirty
  704. //
  705. // notifies the property page site of changes
  706.  
  707. void CMpegAudEncPropertyPage::SetDirty()
  708. {
  709.     m_bDirty = TRUE;
  710.     if (m_pPageSite)
  711.         m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  712. }
  713.  
  714.